home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 17 / AMIGAplus Sonderheft 17 (1999)(ICP)(DE)[!].iso / dsound / source.lha / ARexx.c next >
C/C++ Source or Header  |  1994-07-18  |  2KB  |  97 lines

  1.  
  2. /*ARexx.c:  This is the ARexx support code module*/
  3.  
  4. #include <exec/types.h>
  5. #include <intuition/intuition.h>
  6. #include <clib/intuition_protos.h>
  7. #include <clib/exec_protos.h>
  8. #include "minrexx.h"
  9. #include "arexx.h"
  10. #include <strings.h>
  11. #include <ctype.h>
  12. #include <stdlib.h>
  13.  
  14. #include <pragmas/exec_pragmas.h>
  15. #include <pragmas/intuition_pragmas.h>
  16. #include <pragmas/dos_pragmas.h>
  17.  
  18. extern struct Library *SysBase;
  19. extern struct Library *IntuitionBase;
  20.  
  21. struct RexxMsg *rexxMsg;
  22. BOOL rexxAbort=FALSE;
  23.  
  24. extern char *version;       /*DSound's version string*/
  25.  
  26. void rQuit(char *p);
  27.  
  28. struct rexxCommandList commandList[] =
  29. {
  30.    { "quit" , (APTR)&rQuit },     /*Quit*/
  31.    { NULL, NULL }
  32. };
  33.  
  34. char portName[16];
  35. char arexxBuf[140];
  36.  
  37.  
  38. /*Open the ARexx port*/
  39. long initRexxPort(void)
  40. {
  41.    determinePortName(portName);  /*Get the port name*/
  42.  
  43.    /*Ask minrexx to open the port and return the port's signal bit*/
  44.    return(upRexxPort(portName,commandList,"rx",(APTR)&disp));
  45. }
  46.  
  47. char *result="RESULT";
  48. UBYTE errorNum=0;
  49.  
  50. /*Determine what the ARexx port name should be.  The first running instance*/
  51. /*of DSound should have an ARexx port named 'DSound.1'.  The second, 'DSound.2'*/
  52. /*etc.    This starts at 'DSound.1' and works up until it finds a free space*/
  53. /*(up to DSound.99)*/
  54. void determinePortName(char *portName)
  55. {
  56.    ULONG c=1;
  57.    UBYTE len;
  58.  
  59.    strcpy(portName,"DSound.");
  60.  
  61.    do
  62.    {
  63.       len=stcu_d(&portName[7],c++);
  64.       portName[7+len]=NULL;
  65.    }
  66.    while(FindPort(portName)!=NULL && c<1000);
  67.    if(FindPort(portName)!=NULL)
  68.       exit(50);
  69.    return;
  70. }
  71.  
  72. /*The ARexx command dispatch function.    This calls the functions associated*/
  73. /*with a particular command*/
  74. int disp(struct RexxMsg *msg,struct rexxCommandList *dat,char *p)
  75. {
  76.    rexxMsg=msg;
  77.  
  78.    /*Call the function that supports the command*/
  79.    ((int (*)())(dat->userdata))(p);
  80.  
  81.    /*Reply to ARexx, using the reply string and error number set by the*/
  82.    /*function just called*/
  83.    replyRexxCmd(rexxMsg,errorNum,0,arexxBuf);
  84.    errorNum=0;
  85.    return(1);  /*1 means that minrexx shouldn't reply to the rexx message*/
  86. }
  87.  
  88. /*Quit DSound*/
  89. void rQuit(char *p)
  90. {
  91.    rexxAbort=TRUE;
  92.    strcpy(arexxBuf,result);
  93. }
  94.  
  95. /*End of ARexx.c*/
  96.  
  97.